#include "MenuBar.hpp"
#include "MainView.hpp"
#include "constants.hpp"
using namespace m3g_viewer;

static void callback_quit             (Fl_Window* w, void* v);
static void callback_open_file        (Fl_Window* w, void* v);
static void callback_show_tree_view   (Fl_Window* w, void* v);
static void callback_show_object_view (Fl_Window* w, void* v);
static void callback_show_help_view   (Fl_Window* w, void* v);


MenuBar:: MenuBar (MainView* view) : Fl_Menu_Bar (MENU_BAR_X,
                                                  MENU_BAR_Y,
                                                  MENU_BAR_WIDTH,
                                                  MENU_BAR_HEIGHT),
                                     main_view(view)
{
    Fl_Menu_Item menu_items[] = {
        // File
        {"ファイル(F)", 'f', 0, 0, FL_SUBMENU},
        {"開く", 'o', (Fl_Callback*)callback_open_file, main_view},
        {"アプリケーションの終了", 'q', (Fl_Callback*)callback_quit, main_view},
        {0},
        
        // View
        {"表示(V)", 'v', 0, 0, FL_SUBMENU},
        {"ツリービュー"      , 0, (Fl_Callback*)callback_show_tree_view, main_view},
        {"オブジェクトビュー", 0, (Fl_Callback*)callback_show_object_view, main_view},
        {0},

        // Help
        {"ヘルプ(H)", 'h', 0, 0, FL_SUBMENU},
        {"バージョン", 0, (Fl_Callback*)callback_show_help_view, main_view},
        {0},

        {0}
    };
    copy (menu_items);

    box (FL_THIN_UP_BOX);
}

MenuBar:: ~MenuBar ()
{

}


static
void callback_quit (Fl_Window* w, void* v)
{
    MainView* view = (MainView*)v;
    view->quit ();
}

static
void callback_open_file (Fl_Window* w, void* v)
{
    MainView* view = (MainView*)v;
    view->open_file_dialog ();
}

static
void callback_show_tree_view (Fl_Window* w, void* v)
{
    MainView* view = (MainView*)v;
    view->show_tree_view ();
}

static
void callback_show_object_view (Fl_Window* w, void* v)
{
    MainView* view = (MainView*)v;
    view->show_object_view (0);
}

static
void callback_show_help_view (Fl_Window* w, void* v)
{
    MainView* view = (MainView*)v;
    view->show_help_view ();
}

